<%@ page import="com.jfinal.plugin.activerecord.Db" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    String webPath= Db.queryStr("select value from sys_config where element='domain' ");

    webPath=webPath.replace("applogin.19xw.cn","mz.19xw.net");
%>
<html>
<head>
    <head>
        <title>Title</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    </head>
</head>
<body>
<br><br><br>
<button class="layui-btn" id="add" >添加类型</button>
<input name="cType" value="${cType}" type="hidden">

&nbsp;&nbsp;&nbsp;&nbsp;
<div class="layui-input-inline" style="height: 1rem;padding-bottom: 19px;">


    <select id="cType" style="height: 2.2rem">
        <option name="cType" value="0" ${cType==0?'selected':''}>pc商品</option>
        <option name="cType" value="1" ${cType==1?'selected':''}>移动端商品</option>
        <option name="cType" value="2" ${cType==2?'selected':''}>支付宝商品</option>
        <option name="cType" value="3" ${cType==3?'selected':''}>小程序1商品</option>
        <option name="cType" value="4" ${cType==4?'selected':''}>小程序2商品</option>
        <option name="cType" value="5" ${cType==5?'selected':''}>小程序3商品</option>
        <option name="cType" value="6" ${cType==6?'selected':''}>小程序4商品</option>
        <option name="cType" value="7" ${cType==7?'selected':''}>app端</option>

    </select>
</div>

<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>

<div class="layui-form">
    <form class="layui-form" action="">
        <table class="layui-table">
            <colgroup>
                <col width="100">
                <col width="100">
                <col width="100">
                <col width="100">
                <col width="100">
                <col width="200">
            </colgroup>
            <thead>
            <tr>
                <th>名称</th>
                <th>logo</th>
                <th>序号</th>
                <th>创建时间</th>
                <c:if test="${cType==3}"><th>支付宝链接</th></c:if>
                <c:if test="${cType==5}"><th>支付宝链接(柠檬时代)</th></c:if>


                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="cl">
                <tr>
                    <td>${cl.name}</td>
                    <td><img src="${cl.logo}" width="100rem" height="100rem"></td>
                    <td>${cl.number}</td>
                    <td>${cl.createTime}</td>

                    <c:if test="${cType==3}">

                        <td><%="http://"+webPath+"/apply/login?classId=" %>${cl.id}</td>

                    </c:if>


                    <c:if test="${cType==5}"><td><%="http://alyPayApplet.19xw.net/limo/login?classId=" %>${cl.id}</td></c:if>



                    <td>
                        <button type="button" class="layui-btn" onclick="update('${cl.id}');">修改</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="layui-btn layui-btn-danger" onclick="delProduct('${cl.id}');">删除</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="layui-btn layui-btn-normal" onclick="classListA('${cl.id}');">卡种管理</button>

                    </td>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>

    <div id="fenye"></div>
    <div id="under" style="margin-top: 20rem"></div>
</div>

<%--    分页--%>

<script>

    layui.use('laypage', function(){
        var laypage = layui.laypage;


        laypage.render({
            elem: 'fenye'
            ,count: ${pageUtil.totalRows}
            ,limit:4//数据总数，从服务端得到
            ,curr:${pageUtil.currentPage}
            ,hash:true
            ,jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                console.log(obj.limit); //得到每页显示的条数
                var cType=$("#cType").val();
                console.log(cType);
                //首次不执行
                if(!first){
                    window.location.href="/shop/classTypeList?page="+obj.curr+"&limit="+obj.limit+"&cType="+cType;
                }
            }
        });

    });

</script>

<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        $(document).on('click','#add',function(){
            layer.open({
                type: 2,
                area: ['80%', '80%'],
                offset: '20px',
                shadeClose:true,
                content: '/shop/editClassType?id=&cType='+$("#cType").val(),
                end:function () {
                    console.log("页面要刷新");
                    window.location.reload();
                }
            });
        });
        $(document).on('change','#cType',function(){
            var cType=$("#cType").val();
            console.log(cType);
            window.location.href="/shop/classTypeList?page="+"1"+"&limit=4"+"&cType="+cType;
        });
    });
    function update(id) {
        console.log($("#cType").val());
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            offset: '20px',
            shadeClose:true,
            content: '/shop/editClassType?id='+id+'&cType='+$("#cType").val(),
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }


    /**
     * 打开facevalue页面
     * @param id classType的id
     */
    function classListA(id){
        layer.open({
            type: 2,
            area: ['99%', '85%'],
            offset: '1rem',
            shadeClose:true,
            content: '/shop/commodityList?type='+$("#cType").val()+"&classId="+id,
            end:function () {
                console.log("页面要刷新");
                //window.location.reload();
            }
        });
    }



    function delProduct(id) {
        $.ajax({
            url:'/shop/delClassType',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                id:id,
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(dataA){

                if (dataA.result){
                        window.location.reload();
                    // 获得frame索引
                }else {

                    layer.msg(dataA.msg,{time:3000,icon: 5});
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })
    }
</script>
</body>
</html>
